package com.mw.service;

import com.mw.domain.User;
import com.mw.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    UserRepository userRepository;

    public String getUsernameById(int id){
        User u = userRepository.findById(id);
        return u.getUsername();
    }

    public User getUserById(int id){
        return userRepository.findById(id);
    }

    public User getUserByUP(String username,String password){
        return userRepository.findByUsernameAndPassword(username,password);
    }

    public void saveUser(User user){
        userRepository.save(user);
    }

    public User getUserByUsername(String username){
        return userRepository.findByUsername(username);
    }

}
